package org.nowcoder.leetcode.BTree;

/**
 * Title  : 100. Same Tree
 * Source : https://leetcode.cn/problems/same-tree/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-08-29
 */

public class LeetCode_100 {
    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        //递归遍历比较
        if (p == null) {
            return q == null;
        } else {
            if (q != null) {
                if (p.val == q.val) {
                    return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
                }
            }
            return false;
        }
    }
}
